package com.frank.oj.controller.oj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.frank.oj.annotation.AnonApi;
import com.frank.oj.common.result.CommonResult;
import com.frank.oj.model.entity.RecentContest;
import com.frank.oj.model.vo.*;
import com.frank.oj.service.oj.HomeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author frank
 * @Date 2023/12/20
 */
@RestController
@RequestMapping("/api")
@AnonApi
public class HomeController {

    @Resource
    private HomeService homeService;

    /**
     * 获取最近14天的比赛信息列表
     */
    @GetMapping("/get-recent-contest")
    public CommonResult<List<ContestVO>> getRecentContest() {
        return homeService.getRecentContest();
    }

    /**
     * 获取首页轮播图信息
     */
    @GetMapping("/home-carousel")
    public CommonResult<List<HashMap<String,Object>>> getHomeCarousel(){
        return homeService.getHomeCarousel();
    }

    /**
     * 做题榜单（近七天）
     */
    @GetMapping("/get-recent-seven-ac-rank")
    public CommonResult<List<ACMRankVO>> getRecentSevenACRank() {
        return homeService.getRecentSevenACRank();
    }

    /**
     * 获取最近更新的题目
     * @return
     */
    @GetMapping("/get-recent-updated-problem")
    public CommonResult<List<RecentUpdatedProblemVO>> getRecentUpdatedProblemList() {
        return homeService.getRecentUpdatedProblemList();
    }

    /**
     * 获取网站配置
     */
    @GetMapping("/get-website-config")
    public CommonResult<Map<Object, Object>> getWebConfig() {
        return homeService.getWebConfig();
    }

    /**
     * 获取公告
     * @param limit 每页条数（默认为10）
     * @param currentPage 页数（默认为1）
     */
    @GetMapping("/get-common-announcement")
    public CommonResult<IPage<AnnouncementVO>> getCommonAnnouncement(@RequestParam(value = "limit", required = false) Integer limit,
                                                                     @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return homeService.getCommonAnnouncement(limit, currentPage);
    }

    /**
     * 获取最近一周的提交统计
     */
    @GetMapping("/get-last-week-submission-statistics")
    public CommonResult<SubmissionStatisticsVO> getLastWeekSubmissionStatistics(
            @RequestParam(value = "forceRefresh", defaultValue = "false") Boolean forceRefresh) {
        return homeService.getLastWeekSubmissionStatistics(forceRefresh);
    }

    /**
     * 获取最近其他比赛
     */
    @GetMapping("/get-recent-other-contest")
    public CommonResult<Map<String,Object>> getRecentOtherContest() {
        return homeService.getRecentOtherContest();
    }
}
